package com.hsck.order.kds.setup.fragment.dyjgl

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.hsck.order.kds.R
import com.hsck.order.kds.base.isnoam.view.BaseFragment
import com.hsck.order.kds.databinding.FragmentCxzdBinding
import com.hsck.order.kds.databinding.FragmentDyjglBinding
import com.hsck.order.kds.setup.SetupActivity
import com.hsck.order.kds.setup.adapter.CxzdAdapter
import com.hsck.order.kds.setup.adapter.DyjglAdapter
import com.hsck.order.kds.setup.fragment.cxzd.CxzdDetailsFragment

/**
 * 打印机管理
 */
class DyjglFragment : BaseFragment<FragmentDyjglBinding>(), SetupActivity.UpdatableFragment {

    private val adapter by lazy { DyjglAdapter(R.layout.item_dyjgl) }

    override fun inflateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentDyjglBinding {
        return FragmentDyjglBinding.inflate(inflater)
    }

    override fun loadDataOnce() {
        super.loadDataOnce()
        binding.apply {
            rvDyjgl.layoutManager = GridLayoutManager(requireActivity(), 2)
            rvDyjgl.adapter = adapter
            adapter.datas = listOf("Add", "", "", "", "", "", "")

        }

        adapter.onItemClick = {
            var addPrinterFragment = AddPrinterFragment()//设备管理
            val activity = requireActivity() as SetupActivity
            if (it == "Add") {
                addPrinterFragment.type = "Add"
            } else {
                addPrinterFragment.type = "Edit"
            }
            addPrinterFragment.topFragment = this
            activity.switchFragment(addPrinterFragment)

        }

    }

    override fun onFragmentVisible() {
        //可见
        if (_binding != null) {

        }
    }

    override fun onFragmentInvisible() {
        //不可见

    }
}